//
//  RBDZJokeTableViewCell.m
//  rubaoduanzi
//
//  Created by 李云飞 on 16/9/13.
//  Copyright © 2016年 liyunfei. All rights reserved.
//

#import "RBDZJokeTableViewCell.h"

@implementation RBDZJokeTableViewCell

- (void)awakeFromNib {
    // Initialization code
}
-(void)setJokeModel:(RBDZJokeModel *)jokeModel{
    _jokeModel=jokeModel;

    self.titleLabel.text=[self filterHTML:_jokeModel.title];
    _titleLabel.textColor=[UIColor blackColor];
    [_zanBtn setTitle:[NSString stringWithFormat:@"%@",_jokeModel.up] forState:UIControlStateNormal];
    [_xunBtn setTitle:[NSString stringWithFormat:@"%@",_jokeModel.down] forState:UIControlStateNormal];
    NSDictionary *dict=@{NSFontAttributeName:[UIFont systemFontOfSize:18]};
    CGRect rect=[_jokeModel.content boundingRectWithSize:CGSizeMake(self.cellView.frame.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil];
    self.labelText.frame=CGRectMake(self.cellView.frame.origin.x+Margin,CGRectGetMaxY(self.titleLabel.frame)+Margin*2, rect.size.width-Margin*2, rect.size.height);
    self.labelText.textAlignment=NSTextAlignmentLeft;
    self.labelText.font=[UIFont systemFontOfSize:18];
    self.labelText.numberOfLines=0;
   self.labelText.text=[self filterHTML:_jokeModel.content];
    [self.contentView addSubview:self.labelText];
}
+(instancetype)jokeTableViewCell{
    return [[[NSBundle mainBundle]loadNibNamed:@"RBDZJokeTableViewCell" owner:nil options:nil] lastObject];
}
-(UILabel *)labelText{
    if (!_labelText) {
        _labelText=[[UILabel alloc]init];
    }
    return _labelText;
}
-(NSString *)filterHTML:(NSString *)html{
    //创建扫描对象,消除html转义符号
    NSScanner * scanner = [NSScanner scannerWithString:html];
    NSString * text1 = nil;
    NSString *text2=nil;
    while([scanner isAtEnd]==NO)
    {
        //找到标签的起始位置
        [scanner scanUpToString:@"<"intoString:nil];
        //找到标签的结束位置
        [scanner scanUpToString:@">"intoString:&text1];
        //替换字符
        html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@>",text1]withString:@""];
        [scanner scanUpToString:@"&" intoString:nil];
        [scanner scanUpToString:@";" intoString:&text2];
        html=[html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@;",text2] withString:@""];
    }
    return html;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
#pragma mark 点赞事件
- (IBAction)zanTap:(UIButton *)sender {
}
#pragma mark 逊色事件
- (IBAction)xunTap:(UIButton *)sender {
}
#pragma mark 评论事件
- (IBAction)commentTap:(UIButton *)sender {
}
#pragma mark 更多事件
- (IBAction)moreTap:(UIButton *)sender {
}



@end
